package org.hishen.example.service.admin.mall;

import javax.annotation.Resource;

import org.hishen.example.entity.mall.Category;
import org.hishenframework.core.hibernate.EasyOperater;
import org.hishenframework.data.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CategoryService {

	@Resource
	private EasyOperater op;
	
	/**
	 * 列表
	 * @param page
	 */
	public void list(Page page) {
		op.list(page, "from Category");
	}
	
	/**
	 * 通过主键获取一个Category
	 * @param id
	 * @return
	 */
	public Category get(int id) {
		return op.load(Category.class, id);
	}
	
	/**
	 * 保存
	 * @param category
	 */
	public void save(Category category) {
		op.save(category);
	}
	
	/**
	 * 修改
	 * @param category
	 */
	public void update(Category category) {
		op.update(category);
	}
	
	/**
	 * 删除
	 * @param categories
	 */
	public void delete(Object[] id) {
		StringBuilder hql = new StringBuilder("delete from Category where id in(");
		for (int i = 0; i < id.length; i++) {
			hql.append("?, ");
		}
		hql.delete(hql.length() - 2, hql.length()).append(")");
		op.executeUpdate(hql.toString(), id);
	}
}
